﻿AB.namespace("BD_Product.Mgr");
BD_Product.Mgr = {
    commandHandler: function (command, record) {
        var FId = record.data.ProductId;
        switch (command) {
            case "Edit":
                FIdH.setValue(FId);
                PordEidtStore.load();
                break;
            case "Delete":
                Ext.Msg.confirm('提示', '确定要删除该记录吗?', function (btn) {
                    if (btn == "yes") {
                        Ext.Ajax.request({
                            url: "/Product/DeleteProduct",
                            method: 'post',
                            params: {
                                fId: FId
                            },
                            success: function (result) {
                                if (!isTimeOut(result)) {
                                    var response = Ext.util.JSON.decode(result.responseText);
                                    if (response.success == false) {
                                        ajaxFailureHandler(response);
                                    } else {
                                        ProductListStore.reload();
                                        EditFormPanel.form.reset();
                                        FIdH.setValue(null);
                                        alert("数据删除成功！");
                                    }
                                }
                            }
                        });
                    }
                });
                break;
        }
    },
    successHandler: function (form, action) {
        if (!isTimeOut(action.response)) {
            ProductListStore.reload();
            FIdH.setValue(action.result.extraParams.msg);
            PordEidtStore.load();
            alert("数据保存成功！");
        }
    },
    failureHandler: function (form, action, failureCallback) {
        failureHandler(form, action);
    },
    successCallback: function () {
    },
    failureCallback: function () {
    },
    formStoreLoaded: function (store, records) {
        var formObj = Ext.getCmp("EditFormPanel");
        formStoreLoaded(store, records, formObj);
    },
    searchList: function () {
        ProductListStore.reload();
    },
    resetSearchFrom: function () {
        var formObj = Ext.getCmp("SearchFormPanel");
        formObj.reset();
    },
    Print: function () {
        var fNumber = InputQ_ProductNumber.getValue();
        var fName = InputQ_ProductName.getValue();
        var fModelId = InputQ_ModelTypeSelect.getValue();
        var fReMark = InputQ_ProductRemark.getValue();
        var fProdInvStatusName = InputQ_ProductInvStatus.getValue();
        var sort = ProdctSortColumn.Value;
        var dir = ProdNumSortDirect.Value;
        window.open("/Product/ExportProductInfosToExcel?fNumber=" + fNumber + "&fName=" + fName + "&fModelId=" + fModelId + "&fReMark=" + fReMark + "&fProdInvStatusName=" + fProdInvStatusName + "&sort=" + sort + "&dir=" + dir);
    }
}